package com.julis.activity.setting.flowline;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.Constant;
import com.baseutils.SpfUtils;
import com.github.czy1121.view.RoundButton;
import com.julis.R;
import com.julis.activity.MainActivity;
import com.julis.activity.dengluzhuce.Login_Activity;
import com.suke.widget.SwitchButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 流水线检测设置
 */
public class Setting_Flowline_Activity extends Activity {


    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.tv_inputvin)
    TextView tvInputvin;
    @BindView(R.id.button_checkvin)
    SwitchButton buttonCheckvin;
    @BindView(R.id.tv_inpuobu)
    TextView tvInpuobu;
    @BindView(R.id.button_inpueobu)
    SwitchButton buttonInpueobu;


    @BindView(R.id.tv_bluetooth)
    TextView tvBluetooth;
    @BindView(R.id.button_bluetooth)
    SwitchButton buttonBluetooth;
    @BindView(R.id.tv_checkpsam)
    TextView tvCheckpsam;
    @BindView(R.id.button_checkpsam)
    SwitchButton buttonCheckpsam;
    @BindView(R.id.tv_kl15)
    TextView tvKl15;
    @BindView(R.id.button_kl15)
    SwitchButton buttonKl15;
    @BindView(R.id.logout)
    RoundButton logout;
    @BindView(R.id.activity_seetting)
    LinearLayout activitySeetting;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settingflowline);
        ButterKnife.bind(this);
        boolean Check_Vin = (boolean) SpfUtils.get(this, Constant.Check_Vin, true);

        boolean Check_kl15 = (boolean) SpfUtils.get(this, Constant.Check_kl15, true);
        boolean Check_Bluetooth = (boolean) SpfUtils.get(this, Constant.Check_Bluetooth, true);
        boolean Inpue_Obu = (boolean) SpfUtils.get(this, Constant.Inpue_Obu, true);

        buttonCheckvin.toggle();     //switch state

        buttonKl15.toggle();
        buttonInpueobu.toggle();
        buttonBluetooth.toggle();

        if (Check_Vin) {
            buttonCheckvin.setChecked(true);
        } else {
            buttonCheckvin.setChecked(false);
        }
        if (Check_kl15) {
            buttonKl15.setChecked(true);
        } else {
            buttonKl15.setChecked(false);
        }

        if (Check_Bluetooth) {
            buttonBluetooth.setChecked(true);
        } else {
            buttonBluetooth.setChecked(false);
        }
        if (Inpue_Obu) {
            buttonInpueobu.setChecked(true);
        } else {
            buttonInpueobu.setChecked(false);
        }




        buttonCheckvin.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked) {
                    SpfUtils.put(Setting_Flowline_Activity.this,  Constant.Check_Vin, true);
                } else {
                    SpfUtils.put(Setting_Flowline_Activity.this,  Constant.Check_Vin, false);
                }

            }
        });


        buttonKl15.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked) {
                    SpfUtils.put(Setting_Flowline_Activity.this, Constant.Check_kl15, true);
                } else {
                    SpfUtils.put(Setting_Flowline_Activity.this, Constant.Check_kl15, false);
                }

            }
        });
        buttonBluetooth.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked) {
                    SpfUtils.put(Setting_Flowline_Activity.this, Constant.Check_Bluetooth, true);
                } else {
                    SpfUtils.put(Setting_Flowline_Activity.this, Constant.Check_Bluetooth, false);
                }

            }
        });
        buttonInpueobu.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked) {
                    SpfUtils.put(Setting_Flowline_Activity.this,  Constant.Inpue_Obu, true);
                } else {
                    SpfUtils.put(Setting_Flowline_Activity.this,  Constant.Inpue_Obu, false);
                }

            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }


    @OnClick({R.id.img_back,   R.id.logout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;



            case R.id.logout:
                MainActivity.ActivityA.finish();
                SpfUtils.put(this, "islogin", false);
                Toast.makeText(this, "退出成功！", Toast.LENGTH_SHORT).show();
                finish();
                startActivity(new Intent(Setting_Flowline_Activity.this, Login_Activity.class));
                break;
        }
    }
}



